<?php 
	$state = $_GET['state'];
	$code =  $_GET['code'];
	
	$post_data = array(
	    'grant_type' => 'authorization_code',
	    'code' => $code,
	    'client_id' => 'kpvcrh7lhxikf8vl95a0uwa6uq97t9sq',
		'client_secret' => 'dv5B8RA7uULqfiF7QoyPr5DxhjnhXDxa'
	);	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, 'https://api.box.com/oauth2/token');
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
	$tmp = curl_exec($ch);
	
	$result = json_decode($tmp); 
	
	$home = "index.php?access_token=".$result->{'access_token'}."&refresh_token=".$result->{'refresh_token'};
	
	header('Location: '.$home); 
?>